1. Field of the Invention
The present invention relates to communication of digital data. More specifically, the present invention relates to a method and an apparatus for detecting underflow or overflow conditions within a ring buffer.
2. Related Art
As data transfer rates within computer systems continue to increase, it is becoming harder to coordinate the sending and receiving of data between computer system components. Data is typically transferred between computer system components under control of a global clock signal that is used to control when data is sent and received.
As clock frequencies are increased to provide faster data transfer rates, clock skew can become a significant problem. Clock skew causes a global clock signal to arrive at various computer system components at different and unpredictable times. Hence, a first component that sends data to a second component cannot be certain when the data will be latched by the second component. Clock skew is especially significant between computer system components that are located on different modules or on different chips.
One way to remedy some of the communication problems involved in transferring data between computer system components is to buffer data transfers between computer system components using a FIFO that is implemented as a ring buffer. A ring buffer typically includes an array of data entries as well as a read pointer and a write pointer. As data arrives at the ring buffer, it is stored in the ring buffer using the write pointer to advance through the array and store consecutive data items in consecutive locations in the array. When the write pointer reaches the end of the array it wraps around to the beginning. On the receiving side, the read pointer is used to retrieve consecutive data items from the array.
Unfortunately, a ring buffer can be prone to overflow and underflow errors. An overflow error occurs when the array becomes full and write pointer advances through the read pointer, causing data to be overwritten before it can be read. An underflow error occurs when the array becomes empty and the read pointer advances through the write pointer and reads entries before they are written.
Flow errors, such as underflow errors or overflow errors, typically cannot be detected by examining data as it is received. Conventional error detecting and error correcting techniques (such as error correcting codes and error detecting codes) are able to detect when one or more bits in a data word are changed during a data transfer. However, they cannot detect when an entire data word is substituted as the result of an overflow or an underflow error.
In a particularly versatile implementation, write pointer logic uses a clock associated with the data arriving from a remote source, while read pointer logic uses a local clock. The use of multiple clocks makes flow error detection particularly difficult.
What is needed is a method and an apparatus that allows overflow and underflow errors to be detected by examining data that is received at the end of a data transfer process.
One embodiment of the present invention provides a system for detecting underflow and overflow errors arising within a ring buffer. When the system receives a data word to be transferred through the ring buffer, the system generates a flow indicator value to be stored with the data word in the ring buffer. This flow indicator value contains information that facilitates determining if an underflow has occurred while reading from the ring buffer, or if an overflow has occurred while writing to the ring buffer. Next, the system writes the data word along with the flow indicator value into an entry in the ring buffer. At a later time, the system reads the entry from the ring buffer and generates a predicted flow indicator value. The system compares the flow indicator value read from the ring buffer with the predicted flow indicator value. If the flow indicator value differs from the predicted flow indicator value, the system generates an error signal indicating that an underflow or an overflow has occurred.
In one embodiment of the present invention, the flow indicator value periodically changes, so that a predictably different flow indicator value is written into the entry in the ring buffer upon successive write operations to the entry. This predictably different flow indicator value allows the system to detect an underflow condition or an overflow condition by comparing the flow indicator value with the predicted flow indicator value. If the flow indicator value read from the ring buffer differs from the predicted flow indicator value, an underflow condition or overflow condition has occurred.
In one embodiment of the present invention, the flow indicator value includes a single bit that changes every time a write pointer for the ring buffer reaches a maximum value.
In one embodiment of the present invention, the flow indicator value is encoded as changes between even and odd parity within a parity bit in the data word.
In one embodiment of the present invention, the ring buffer is of odd size and the flow indicator value is a single bit that alternates between zero and one on successive write operations.
In one embodiment of the present invention, the flow indicator value is encoded as changes between even and odd parity in a parity bit in the data word. Furthermore, the ring buffer is of odd size and the parity bit alternates between even and odd parity on successive write operations.
In one embodiment of the present invention, the flow indicator value further includes a flow direction indicator that allows an underflow error to be differentiated from an overflow error.